A computer virtualization technology is a decoupling method for separating a lower-layer hardware device from an upper-layer operating system and application of a computer. The computer virtualization technology introduces a Virtual Machine Monitor (VMM) layer to directly manage lower-layer hardware resources and create a VM unrelated to lower-layer hardware for the upper-layer operating system and the application to use. A corresponding VM architecture is shown in FIG. 1. As one of important lower-layer support technologies for a currently popular cloud computing platform, the virtualization technology can greatly increase resource use efficiency of a physical device. Compared with a conventional physical machine, the VM has better isolation and encapsulation characteristics. Information of the whole VM can be saved in a Virtual Disk Image (VDI), so as to conveniently perform operations such as snapshot taking, backing up, cloning, and distribution on the VM.
A Virtual Disk (VDisk) is a virtual storage device provided by the VMM for the VM to use. Physical storage space corresponding to the VDisk may be a local storage system of a host or a network storage system of a data center, such as, a Network Attached Storage (NAS) file server, a Storage Area Network (SAN), a storage cluster, or a storage cloud. The VDisk may exist in the host in the form of a file or a block device (such as a disk partition or a logical volume).
VM storage space is generally allocated in the following two manners: pre-allocation and dynamic allocation. In the pre-allocation, storage space having a designated size is allocated to each VM at a time. When VM data is less, the pre-allocation generates a large space waste. The dynamic allocation of virtual storage space may reduce a storage resource waste to a certain extent. At the beginning, the virtual storage space occupies small actual storage space. With the use of a user, more and more files are created in the VM storage space, and larger and larger storage space is occupied.
Although the existing method for managing the storage space through the dynamic allocation can perform the allocation according to requirements, when a file deletion operation is performed in the VM, if the host cannot perceive the operation, the host cannot release free space that is already released by the VM. For example, a VM having a 20 GB virtual storage device basically uses up all the storage space as temporary files during a busiest task. When the task is idle, the temporary files are deleted, and 15 GB free space exists in the system, but storage resources of the host occupied by the 15 GB free space are not released.
In the prior art, virtual computer software VM ware Workstation provides a VM ware Shrinking Virtual Disk function, which can release free data blocks (hereinafter, blocks) in a VM Ware Virtual Machine Disk Format (VMDK) dynamic VDisk. The main steps are as follows.
Perform disk defragmentation in the VM (optional).
Set free blocks in the VDisk to zero through VM Tools in the VM.
A supporting tool in the host scans a file or a block device corresponding to the VDisk to identify the “zero” blocks, and perform image shrinking by using dynamic image format characteristics to complete release of the free data blocks.
In the foregoing method, in the process in which the VM Tools sets the free blocks in the VDisk to zero, a write operation needs to be performed on all the free blocks, and when the host identifies the “zero” blocks, a read operation needs to be performed on all the data blocks. That is, in the existing method, high operation overhead exists, and too many disk read and write operations waste a large amount of disk bandwidth and spend a long time. Moreover, in the existing method, the host indirectly judges space occupation of each data block in the VDisk by identifying the “zero” blocks, so global free data block information of a disk of the VM cannot be acquired in real time. Moreover, application of the existing method is limited, and the method is only applicable to the dynamic allocation image format. For a pre-allocation mirror format, the free blocks cannot be released.